#pragma once
#include <iostream>
#include <functional>

class Task
{
    using func_t = std::function<int(int, int, char)>; // func是一个函数
    // typedef std::function<int(int,int)> func;
public:
    Task() {}

    Task(int x, int y, char op, func_t func)
        : _x(x), _y(y), _op(op), _callback(func) {}

    std::string operator()()
    {
        int result = _callback(_x, _y, _op);
        char buffer[1024];
        snprintf(buffer, sizeof(buffer) - 1, "%d %c %d = %d", _x, _op, _y, result);
        return buffer;
    }

    //返回任务操作的结果
    std::string toString()
    {
        char buffer[1024];
        snprintf(buffer, sizeof(buffer) - 1, "%d %c %d = ?", _x, _op, _y);
        return buffer;
    }

private:
    int _x;
    int _y;
    char _op; // 操作的任务
    func_t _callback;
};